package cn.etgps.etgps.ui;

import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;

import butterknife.Bind;
import butterknife.OnClick;
import cn.etgps.etgps.R;
import cn.etgps.etgps.base.MyBasicActivity;
import cn.etgps.etgps.event.EventBusSendFactory;
import cn.etgps.etgps.event.EventExpenseEntity;

/**
 * Created by xiaoyu on 2016/3/28.
 */
public class TrafficExpenseActivity extends MyBasicActivity {
    private final static String EXPENSE_ENTITY = "expense_entity";
    @Bind(R.id.expense_high_price)
    EditText editHighPrice;
    @Bind(R.id.expense_high_sheet)
    EditText editHighSheet;
    @Bind(R.id.expense_parking_price)
    EditText editParkingPrice;
    @Bind(R.id.expense_parking_sheet)
    EditText editParkingSheet;
    @Bind(R.id.expense_wash_price)
    EditText editWashPrice;
    @Bind(R.id.expense_wash_sheet)
    EditText editWashSheet;
    private EventExpenseEntity eventExpenseEntity;
    private String highPrice = "";
    private String highSheet = "";
    private String parkPrcie = "";
    private String parkSheet = "";
    private String washPrice = "";
    private String washSheet = "";

    public static void gotoTrafficExpenseActivity(MyBasicActivity context, EventExpenseEntity eventExpenseEntity) {
        Intent intent = new Intent(context, TrafficExpenseActivity.class);
        intent.putExtra(EXPENSE_ENTITY, eventExpenseEntity);
        context.startActivity(intent);
    }

    @Override
    protected void setTitle() {
        titleBar.setLeftImageResource(R.mipmap.nav_back);
        titleBar.setLeftText(" ");
        titleBar.setTitle(getResources().getString(R.string.expense_record));
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_traffic_expense;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        if (getIntent() != null && getIntent().hasExtra(EXPENSE_ENTITY)) {
            this.eventExpenseEntity = (EventExpenseEntity) getIntent().getSerializableExtra(EXPENSE_ENTITY);
            if (this.eventExpenseEntity != null) {
                bindView(eventExpenseEntity);
            }
        }
    }

    private void bindView(EventExpenseEntity eventExpenseEntity) {
        editHighPrice.setText(eventExpenseEntity.getHighPrice());
        editHighSheet.setText(eventExpenseEntity.getHighSheet());
        editParkingPrice.setText(eventExpenseEntity.getParkPrcie());
        editParkingSheet.setText(eventExpenseEntity.getParkSheet());
        editWashPrice.setText(eventExpenseEntity.getWashPrice());
        editWashSheet.setText(eventExpenseEntity.getWashSheet());
    }

    @OnClick(R.id.expense_btn_sure)
    public void onClick() {
        highPrice = editHighPrice.getText().toString().trim();
        highSheet = editHighSheet.getText().toString().trim();
        parkPrcie = editParkingPrice.getText().toString().trim();
        parkSheet = editParkingSheet.getText().toString().trim();
        washPrice = editWashPrice.getText().toString().trim();
        washSheet = editWashSheet.getText().toString().trim();
        EventExpenseEntity expenseEntity = new EventExpenseEntity(highPrice, highSheet, parkPrcie, parkSheet, washPrice,
                washSheet);
        EventBusSendFactory.expenseEvent(expenseEntity);
        finish();
    }
}
